<!--
 * @Author: 莫莫
 * @Phone: 13450159681
 * @Description: 
 * @Date: 2024-11-19 15:25:02
 * @LastEditTime: 2024-12-18 21:17:40
-->
<template>
	<view>
		<scroll-view class="rigth hh100" scroll-y="true" :scroll-with-animation="false" :enable-back-to-top="true"
			@scrolltolower="loadmore">
			<block v-if="data.pagination.data.length > 0">
				<view class="date">
					<view class="list d-b-c f-w p30">
						<view class="item mb30" v-for="(item, index) in data.pagination.data" :key="index">
							<image :src="item.goods.image" mode="aspectFill" class="ww100" @click="store.commit('jump', `/pages/detail/detail?id=${item.goods_id}`)"></image>
							<view class="f28 vertical mt10" @click="store.commit('jump', `/pages/detail/detail?id=${item.goods_id}`)">{{item.goods.title}}</view>
							<view class="sub f22 mt5">{{item.updatetime}}<text style="position: relative; right: -24px; color: red;" @click="remove(item.goods_id)">移除</text></view>
						</view>
					</view>
				</view>
			</block>
			<up-empty marginTop="30vh" mode="list" v-else></up-empty>
		</scroll-view>
	</view>
</template>

<script setup>
import { reactive } from 'vue'
import { onLoad } from "@dcloudio/uni-app";
import { useStore } from "vuex"
const store = useStore()
const data = reactive({
	pagination: {
		data: [],
		current_page: 1,
		total: 1,
		last_page: 1,
	},
	loadStatus: '',
	status: "loadmore",
	list: []
})
async function getGoodsList(page = 1, list_rows = 12) {
	data.loadStatus = 'loading';
	const res = await store.dispatch('request', {
		url: store.state.api.user.goods_log.index,
		data: {
			type:'views',
			list_rows,
			page,
		}
	})
	if (res.code == 1) {
		let couponList = data.pagination.data.concat(res.data.data);
		data.pagination = {
			...res.data,
			data: couponList,
		};

		if (data.pagination.current_page < data.pagination.last_page) {
			data.loadStatus = 'more';
		} else {
			data.loadStatus = 'noMore';
		}
	}

}
function remove(goods_id) {
	store.dispatch('request', {
		url: store.state.api.user.goods_log.view_del,
		data: {
			goods_id,
		}
	}).then(res => {
		if (res.code == 1) {
			uni.showToast({
				title: '移除成功',
				icon: 'none',
				duration: 1000,
			});
			data.pagination.data = data.pagination.data.filter(item => item.goods_id !== goods_id);
		}
	})
}
// 加载更多
function loadmore() {
	if (data.loadStatus !== 'noMore') {
		getGoodsList(data.pagination.current_page + 1);
	}
}
onLoad(async (options) => {
	getGoodsList();
});
</script>

<style scoped lang="scss">
.list {
	width: 100%;

	.item {
		width: calc(50% - 15rpx);

		image {
			height: 200rpx;
		}
	}
}
</style>